﻿@model MvcApplication6.Models.EventModel

@{
    ViewBag.Title = "AddNews";
}

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-language" content="ja"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Add News | CÔNG TY TNHH TM DV KT CÔNG NGHỆ AN PHÚ </title>
<meta name="description" content="Camera ip,camera quan sát giá tốt nhất tham khảo tại đây. Lắp đặt hệ thống camera có khuyến mãi, camera giảm giá" />
<meta name="keywords" content="camera, mua camera, lap camera, ban camera, camera ip, camera quan sat, camera giam sat, gia camera, lắp camera, he thong camera, bo camera,ip camera, sua camera, camera quan 1,camera quan 2, camera quan 3, vnpt,camera quan 7, camera quan 1,camera quan 3,camera quan 4,camera quan 5,carera quan 6,camera quan 7,camera quan 8,camera quan 9,camera quan 10,camera quan 11,camera quan 12,camera binh tan,camera binh chanh,camera cu chi,camera hoc mon,lap camera q1,lap camera q2,lap camera q3,lap camera q4,lap camera q5,lap camera q6,lap camera q7,lap camera q8,lap camera q9,lap camera q10,lap camera q11,lap camera q12,lap camera binh tan,lap camera binh chanh,camera gia re, he thong camera, giá camera, gia camera, camera fpt, camera vnpt, Dau ghi, dau ghi camera,lắp camera,camera khong day ip,lap camera gia re, camera quan sat sieu nho, thi cong lap dat camera,camera ip gia re,ban camera gia re,lap camera quan sat,cong ty camera,lắp camera,camera hong ngoai,camera quan sat tu x a,dau ghi hinh" />
<meta name="robots" content="index,follow" />
<link href="../../Content/css/style.css" rel="stylesheet" type="text/css"/>
<link href="../../Content/css/calendar.css" rel="stylesheet" type="text/css"/>
<script src="../../Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../../Scripts/calendar.js" type="text/javascript"></script>
<script src="../../Content/includes/ckeditor/ckeditor.js" type="text/javascript"></script>
<link href="../../Content/includes/ckeditor/contents.css" rel="stylesheet" type="text/css"/>
<link href="../../Content/css/nn-styles.css" rel="stylesheet" type="text/css"/>


<script type="text/javascript">
    $(document).ready(function () {
        var fileName2 = "";
        $("#Upload").click(function () {
            var formData = new FormData();
            var totalFiles = document.getElementById("FileUpload").files.length;
            for (var i = 0; i < totalFiles; i++) {
                var file = document.getElementById("FileUpload").files[i];
                fileName2 = file;
                formData.append("FileUpload", file);
            }
            $.ajax({
                type: "POST",
                url: '/Admin/UploadImage2',
                data: formData,
                dataType: 'json',
                contentType: false,
                processData: false,
                success: function (response) {
                    //$("#linkImageUpload").innerHTML = "";
                    //$("#linkImageUpload").append('<span">' + 'http://aptechpro.vn/Upload/Images/' + fileName2.name + '</span>');
                    // $("#linkImageUpload").innerHTML = '<span">' + 'http://aptechpro.vn/Upload/Images/' + fileName2.name + '</span>';
                    $("#linkImageUpload").html('<span">' + 'http://aptechpro.vn/Upload/Images/' + fileName2.name + '</span>');
                    alert('succes!!');
                },
                error: function (error) {
                    alert("errror");
                }
            });
        });
    });

</script>

<script type="text/javascript">
    $(function () {
        $("#datepicker").datepicker({
            showOn: "both",
            buttonImage: "../../Content/images/event-icon.png"
        });
        $("#datepicker1").datepicker({
            showOn: "both",
            buttonImage: "../../Content/images/event-icon.png"
        });
    });

    function ddListChange() {
        var val = $('#dMenu1').val();
        if (val == 7) {
            $('#StartDay').show();
            $('#FinishDay').show();
        }
        else {
            $('#StartDay').hide();
            $('#FinishDay').hide();   
        }
    }
</script>
</head>
<body>

@{
   if(@ViewBag.error == "OK")
   {
      <script type="text/javascript">
          alert("Successfull !!! ..... ");
      </script>
   }
   else
   {
       if (ViewBag.error == "NOT")
       {
          <script type="text/javascript">
              alert("Error !!! ..... ");
          </script>
       }
   }
}

<div>
    <a style="margin-left:127px;margin-top:5px;" href="http://aptechpro.vn/"><b>Trang chủ</b></a>  
    <h1 class="ad-title"><center> Add News </center></h1>

     @using (Html.BeginForm("AddNews", "Admin", FormMethod.Post, new { id = "add_news", name = "add_news", enctype = "multipart/form-data" }))
     {       
        @Html.AntiForgeryToken() <!--Chống giả lập yêu cầu -->
        @Html.ValidationSummary(true) <!-- hiện thị kiểm lỗi phía Server-->
         
        @Html.TextBoxFor(model => model.Id, new { id = "Id", style = "display: none;" })       
        <p>
            <label for="menu1"><b>Category Event:</b></label>
            @Html.DropDownList("IdCe", null, new { style = "width:350px", id = "dMenu1", name = "dMenu1", tabindex = "0", onchange = "ddListChange()" })
            @Html.ValidationMessageFor(model => model.IdCe)
        </p>                            
        <p>
            <label for="title"><b>Tiêu đề: <span style="color:red">*</span></b></label>
            @Html.TextBoxFor(model => model.Title, new { name = "title", type = "text", id = "title", placeholder = "nhập tiêu đề news... ", style = "width:350px;", maxlength = "200" })
            @Html.ValidationMessageFor(model => model.Title)
        </p>
        <p>
            <label for="title"><b>Tiêu đề 2: </b></label>
            @Html.TextAreaFor(model => model.Title2, new { name = "title", id = "title", style = "width:350px;", maxlength = "1000" })
        </p>
        <p>
            <label for="title"><b>Image: </b></label>
            @Html.TextBoxFor(model => model.FileImage, new { name = "title", type = "file", id = "image", style = "width:350px;", maxlength = "200", onchange = "ImageClick()" })
             <div class="div_image" style = "padding-left:294px">
                <img class="image_show" id="show_image" src="../../Upload/Images/@Model.Image" style="width: 150px; height: 200px;">
                @Html.TextBoxFor(model => model.Image, new { id = "name_image", style = "display: none;" })
            </div>	       
        </p>          
         if (Model.IdCe == 7)
         {
            <p id="StartDay">
                <label for="dayBegin"><b>Ngày bắt đầu:</b></label>
                @Html.TextBoxFor(model => model.StartDate, new { id = "datepicker" })
                @Html.ValidationMessageFor(model => model.StartDate)
            </p>
            <p id="FinishDay">
                <label for="dayFinish"><b>Ngày kết thúc:</b></label>
                @Html.TextBoxFor(model => model.EndDate, new { id = "datepicker1" })
                @Html.ValidationMessageFor(model => model.EndDate)
            </p> 
         }
         else
         {
            <p id="StartDay" style = "display: none;">
                <label for="dayBegin"><b>Ngày bắt đầu:</b></label>
                @Html.TextBoxFor(model => model.StartDate, new { id = "datepicker" })
                @Html.ValidationMessageFor(model => model.StartDate)
            </p>
            <p id="FinishDay" style = "display: none;">
                <label for="dayFinish"><b>Ngày kết thúc:</b></label>
                @Html.TextBoxFor(model => model.EndDate, new { id = "datepicker1" })
                @Html.ValidationMessageFor(model => model.EndDate)
            </p>
         }
         <p>
         <label for="title"><b>Image upload: </b></label>
            <input type="file" id="FileUpload"/>
            <input type="button" id="Upload" value="Upload" />
         </p>
         <p>
         <label for="title"><b>Link : </b></label>
            <div id="linkImageUpload">Không có link</div>
         </p>         
        <p>
            <label for="ckeditor"><b>Nội dung: <span style="color:red">*</span></b></label>
            @Html.TextAreaFor(model => model.Content, new { cols = "80", id = "editor", name = "editor", rows = "10" })
			@Html.ValidationMessageFor(model => model.Content)
            <script type="text/javascript">
			    CKEDITOR.replace('editor');
            </script>
        </p>
        <div class="btn-submit">
        @{
         if (@ViewBag.Button == "Edit")
         {
                <input type="submit" name="Command" class="btn_contact" value="Edit" />
         }
         else
         {
                <input type="submit" name="Command" class="btn_contact" value="Create" />
         }            
        }
        </div>
     }
</div><!-- end.content-->

<!--oooooooooooooooooooooooooooooooooooKiem tra anhoooooooooooooooooooooooooooooooooooooooooooooooo -->
<script type='text/javascript'>
    function ImageClick() {
        //When the form is submitted
        //$('form').submit(function (e) {
        //Check that a file exists and that it is of the appropriate extension
        var fileInput = document.getElementById("image");
        var file = fileInput.files[0];

        if (file.name.length > 20) {
            $("#image").val(""); //Gia tri ke chu choose
            $("#show_image").attr("src", "../../Upload/Images/"); //Khung hinh hien thi
            alert("Tên ảnh upload phải nhỏ hơn 20 từ");
        }
        else 
        {
            if (!isValidImage($("#image").val())) 
            {
                //e.preventDefault();
                $("#image").val("");
                $("#show_image").attr("src", "../../Upload/Images/");
                alert("Chọn file ảnh hợp lệ !!! . (.jpg. png .jpeg....)");
            }
            else {
                $("#show_image").attr("src", "../../Upload/Images/" + $("#image").val().replace(/^.*\\/, "")).width(150).height(200);
                $("#name_image").text($("#image").val().replace(/^.*\\/, ""));
            }
        }
    }

    //Helper method to get the file name
    function getExtension(filename) {
        var parts = filename.split('.');
        return parts[parts.length - 1];
    }
    //Helper function to determine if the file type is valid
    function isValidImage(filename) {
        var ext = getExtension(filename);
        switch (ext.toLowerCase()) {
            case 'jpg':
            case 'jpeg':
            case 'gif':
            case 'bmp':
            case 'png':
                //It is an image - allow it
                return true;
        }
        //It wasn't a valid extension - don't submit the form
        return false;
    }
</script>

</body>
</html>